<template>
    <Table :columns="columns" :data="value" :loading="loading">
        <template slot-scope="{ row, index }" slot="attribute">
            <span v-if="row.attribute === 0">良品</span>
            <span v-if="row.attribute === 1">不良品</span>
            <span v-if="row.attribute === 2">可销售不良品</span>
        </template>
        <template slot-scope="{ row, index }" slot="action">
            <Button size="small" @click="submitForDelete(row.id)">删除</Button>
        </template>
    </Table>
</template>

<script>
    export default {
        name: "tabDetail",
        props: {
            value: {
                type: Array,
                default: () => []
            },
            tally: {
                type: Number,
                default: 0
            }
        },
        data(){
            return {
                loading: false,
                columns: [{
                    title: '序号',
                    width: 80,
                    render: (h, {row, column, index}) => {
                        return h('div', index + 1);
                    }
                },{
                    title: '来货条码',
                    key: 'barcode'
                },{
                    title: '数量',
                    key: 'quantity'
                },{
                    title: '批次号',
                    key: 'batch'
                },{
                    title: '属性',
                    slot: 'attribute'
                },{
                    title: '时间',
                    key: 'created_at'
                },{
                    title: '操作',
                    slot: 'action'
                }]
            }
        },
        methods: {
            submitForDelete(id){
                this.loading = true;
                this.$http.delete(`warehousing/tally/${this.tally}/detail/${id}`).then(() => {
                    this.$emit('refresh')
                }).finally(() => {
                    this.loading = false;
                })
            }
        }
    }
</script>

<style scoped>

</style>
